/**
 * Tencent is pleased to support the open source community by making QMUI_iOS available.
 * Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://opensource.org/licenses/MIT
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */

//
//  QMUICommonDefines.h
//  qmui
//
//  Created by QMUI Team on 14-6-23.
//

#ifndef MJUICommonDefines_h
#define MJUICommonDefines_h


#pragma mark - 日志
/// 输出时, 输出函数(方法)名及行数(Release时关闭日志)
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr, "\n[%s %s %s-%d] %s\n", __DATE__ , __TIME__, [[[NSString stringWithUTF8String: __FILE__] lastPathComponent] UTF8String], __LINE__, [[[NSString alloc] initWithData:[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] dataUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding] UTF8String]?[[[NSString alloc] initWithData:[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] dataUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding] UTF8String]:[[NSString stringWithFormat: FORMAT, ## __VA_ARGS__] UTF8String])//NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif


#pragma mark - 尺寸(适配)

#define SCREEN_MAIN ([UIScreen mainScreen].bounds)

/// 旋转后屏幕宽度和高度
#define REAWIDTH (SCREEN_WIDTH > SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT)
#define REAHEIGHT (SCREEN_WIDTH < SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT)

/// 自动适配宽度,width为原始iPhone5/5s的宽度
#define AUTO_MATE_5_WIDTH(width) ((width) * SCREEN_WIDTH/320)
/// 自动适配宽度,width为原始iPhone6/6s的宽度
#define AUTO_MATE_WIDTH(width) ((width) * SCREEN_WIDTH/375)
/// 自动适配高度,width为原始iPhone6/6s的高度
#define AUTO_MATE_HEIGHT(height) ((height) * SCREEN_HEIGHT/667)

#define RatioWIDTH (SCREEN_WIDTH < 375 ? 375 : SCREEN_WIDTH)
/// 适配比例(最低适配375)
#define AdaptationRatio(a) RatioWIDTH/375*a

#pragma mark - 字体
/// 普通字体
#define MJUIFontMake(size) [UIFont systemFontOfSize:size]
/// 粗字体
#define MJUIFontBoldMake(size) [UIFont boldSystemFontOfSize:size]
/// BEBAS字体
#define MJUIFontBebasMake(fontSize) [UIFont fontWithName:@"BEBAS" size:fontSize]



#pragma mark - UIColor
/// UIColor 相关的宏，用于快速创建一个 UIColor 对象，更多创建的宏可查看 UIColor+QMUI.h
#define MJUIColorMake(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
/// r, g, b, a
#define MJUIColorMakeWithRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/1.0]
/// 16进制色
#define MJUIColorFromHex(s) [UIColor colorWithRed:(((s & 0xFF0000) >> 16 )) / 255.0 green:((( s & 0xFF00 ) >> 8 )) / 255.0 blue:(( s & 0xFF )) / 255.0 alpha:1.0]
/// 16进制色
#define MJUIColorFromHex_Alpha(s,a) [UIColor colorWithRed:(((s & 0xFF0000) >> 16 )) / 255.0 green:((( s & 0xFF00 ) >> 8 )) / 255.0 blue:(( s & 0xFF )) / 255.0 alpha:a]

#pragma mark - UIImage
#define MJUIImageMake(img) [UIImage imageNamed:img]


#pragma mark - 导航栏
/// 状态栏高度
#define STATUS_BAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
/// 导航栏高度
#define NAVBAR_HEIGHT [UINavigationController new].navigationBar.bounds.size.height
/// 获取导航栏+状态栏的高度(刘海屏92)
#define STATUS_NAV_HEIGHT  ([UINavigationController new].navigationBar.bounds.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height)
/// 获取控制器内容高度
#define KVIEW_HEIGHT  (SCREEN_HEIGHT - STATUS_NAV_HEIGHT)


#pragma mark - GCD
/// 主线程
#define MJUIMain_GCD(block) dispatch_async(dispatch_get_main_queue(),block)

/// 子线程
#define MJUIBack_GCD(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

/// 延时
#define MJUIAfter_GCD(a, block) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(a* NSEC_PER_SEC)), dispatch_get_main_queue(), block)


#pragma mark - 语言
#define MJUILocalizedString(key) [[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"appLanguage"]] ofType:@"lproj"]] localizedStringForKey:(key) value:nil table:@"Localizable"]


#define MJUILocalizedENString(key) [[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"]] localizedStringForKey:(key) value:nil table:@"Localizable"]

#pragma mark - NSDate
#define MJUIDateFormat @"yyyy-MM-dd HH:mm:ss"
#define MJUIDateFormat1 @"yyyy-MM-dd HH:mm"
#define MJUIDateFormat2 @"yyyy-MM-dd"
#define MJUIDateFormat3 @"HH:mm:ss"
#define MJUIDateFormat4 @"yyyy/M/d HH:mm"
#define MJUIDateFormat5 @"yyyy年M月"
#define MJUIDateFormat6 @"HH:mm"
#define MJUIDateFormat7 @"yyyy/MM/dd"
#define MJUIDateFormat8 @"yyyy年M月d日"
#define MJUIDateFormat9 @"yyyy/M/d"
#define MJUIDateFormat10 @"yyyy-M-d"
#define MJUIDateFormat11 @"M/d"
#define MJUIDateFormat12 @"yyyy年M月d日 HH:mm"
#define MJUIDateFormat13 @"yyyy-M"
#define MJUIDateFormat14 @"yyyy"
#define MJUIDateFormat15 @"M"
#define MJUIDateFormat16 @"MM/dd"
#define MJUIDateFormat17 @"yy/MM/dd"
#define MJUIDateFormat18 @"MM"
#define MJUIDateFormat19 @"yyyy-MM"


#pragma mark - CGRect
#define MJUIFrame(x,y,w,h) CGRectMake((x), (y), (w), (h))

#pragma mark - 字符串
#define MJUIEmptyString(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )

#pragma mark - 数组
#define MJUIEmptyArray(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)

#pragma mark -字典
#define MJUIEmptyDictionary(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)

#pragma mark -UserDefaults
#define MJUIUserDeFault [NSUserDefaults standardUserDefaults]

#pragma mark -弱引用（代码块）
#define WeakSelf(type)  __weak typeof(type) weak##type = type;

#endif
